package cn.tansanqinger.controller.group;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.service.group.IGroupAndNumberService;
import cn.tansanqinger.util.Tools;

@Controller
@RequestMapping("/admin/group")
public class GroupAllController {
	
	@Autowired
	private IGroupAndNumberService service;

	@RequestMapping("/list")
	public ModelAndView list(ModelAndView mv) {
		mv.setViewName("group/list");
		return mv;
	}
	
	/**
	 * 查询全部的群聊信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectGroupAll")
	public @ResponseBody String selectCondition(HttpServletRequest request) {
		try {
			return new ObjectMapper().writeValueAsString(service.selectGroup(request, 0));
		} catch (Exception e) {}
		return null;
	}
	
	
	/**
	 * 查看群聊中用户信息
	 * @param request
	 * @param mv
	 * @return
	 */
	@RequestMapping("/selectGroupNumber")
	public @ResponseBody ModelAndView list3_details(HttpServletRequest request, ModelAndView mv) {
		mv.addObject("account", Tools.isEmpty(request.getParameter("account")));
		mv.addObject("groupNumber", service.selectGroupNumber(request));
		mv.addObject("isbanned", Tools.isEmpty(request.getParameter("isbanned")));
		mv.setViewName("group/selectGroupNumber");
		return mv;
	}
	
}
